package com.loooooo.pm2024.config;

import com.loooooo.pm2024.web.MyFilter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import org.thymeleaf.TemplateEngine;
import org.thymeleaf.spring5.view.ThymeleafViewResolver;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author ytx98
 * @date 2018年6月15日 新建
 */
@Configuration
public class MyWebMvcConfigurer implements WebMvcConfigurer {

    @Value("#{'${spring.resources.static-locations:classpath:/static/}'.split(',')}")
    List<String> pathStatic;

    @Value("#{'${spring.mvc.static-path-pattern:/static/**}'.split(',')}")
    List<String> patternStatic;


    @Resource(name = "thymeleafViewResolver")
    private ThymeleafViewResolver thymeleafViewResolver;

    @Autowired
    MyFilter myFilter;


    @Autowired
    TemplateEngine templateEngine;


    public void addResourceHandlers(ResourceHandlerRegistry registry) {
//        registry.addResourceHandler("/MP_verify_twMtR3JeRgsqZnuF.txt")
//                .addResourceLocations("classpath:/static/MP_verify_twMtR3JeRgsqZnuF.txt");

        registry.addResourceHandler("/favicon.ico")
                .addResourceLocations("classpath:/favicon.ico");

//        registry.addResourceHandler("/static")
//                .addResourceLocations("classpath:/favicon.ico");
    }

    @Bean
    public SqlInjectInterceptor sqlInjectInterceptor(){
        return new SqlInjectInterceptor();
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        //registry.addInterceptor(sqlInjectInterceptor()).addPathPatterns("/**");
        registry.addInterceptor(myFilter);
        //templateEngine.addTemplateResolver(new StringTemplateResolver());
    }

//    @Autowired
//    private SessionPersistenceFilter sessionPersistenceFilter;

    //
//    @Bean
//    public FilterRegistrationBean registerAuthFilter() {
//        FilterRegistrationBean registration = new FilterRegistrationBean();
//        registration.setFilter(sessionPersistenceFilter);
//        registration.addUrlPatterns("/*");
//        registration.setName("authFilter");
//        registration.setOrder(1);  //值越小，Filter越靠前。
//        return registration;
//    }

//    @Bean
//    public StandardDialect myDialect(){
//        return new StandardDialect(){
//            @Override
//            public Set<IProcessor> getProcessors(String dialectPrefix) {
//                Set<IProcessor> processors = new HashSet<>();
//                processors.add(new StaticFunctionProcessor());
//                return processors;
//            }
//        };
//    }

}
